package com.commonlyUsedClass.ObjectStudy;

import java.io.Serializable;
import java.util.Objects;

/***
 * @ClassName: Student
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 15:12 2022/2/14
 * @version : V1.0
 */
public class Student implements Serializable {
    private String name;
    private int age;
    private String sex;


    //重写方法实现判断对象里的值是否一致
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;

        //判断两个娃引用指向的实际对象是否一致，或者存在父子关系
        if (o instanceof Student) {
            //有可能是父子关系，所以需要强制转换类型
            Student o1 = (Student) o;
            if (o1.getName().equals(this.name) && o1.getAge() == this.age && o1.getSex().equals(this.sex)) {
                return true;
            }
        }
        return false;
    }

/*    @Override
    public int hashCode() {
        return Objects.hash(name, age, sex);
    }*/

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public Student setName(String name) {
        this.name = name;
        return this;
    }

    public int getAge() {
        return age;
    }

    public Student setAge(int age) {
        this.age = age;
        return this;
    }

    public String getSex() {
        return sex;
    }

    public Student setSex(String sex) {
        this.sex = sex;
        return this;
    }

    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public Student() {
    }
}
